/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.*;
import com.comac.ins.isfd.domain.bo.query.IsfdMetalMaterialStaticStrengthAnalysisQueryBo;
import com.comac.ins.isfd.domain.thirdParty.*;
import com.comac.ins.isfd.domain.vo.*;
import com.comac.ins.isfd.service.IIsfdDatabaseDataManagementService;
import com.comac.ins.isfd.service.IIsfdDatabaseModelConfigService;
import com.comac.ins.isfd.service.IIsfdThirdPartyAccessService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据库建模后，数据表数据管理
 *
 * @author Lion Li
 * @date 2024-11-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/thirdParty")
@Slf4j
public class IsfdThirdPartyAccessController extends BaseController {

    private final IIsfdDatabaseDataManagementService isfdDatabaseDataManagementService;
    private final IIsfdDatabaseModelConfigService isfdDatabaseModelConfigService;
    private final IIsfdThirdPartyAccessService iIsfdThirdPartyAccessService;

    /**
     * 查询数据库建模配置列表
     */
    @PostMapping("/database/config")
    public TableDataInfo<IsfdDatabaseModelConfigVo> getModelConfig(@RequestBody IsfdDatabaseModelConfigQueryBo bo) {
        return isfdDatabaseModelConfigService.queryPageList(bo);
    }

    /**
     * 批量插入数据到模型库
     */
    @Log(title = "插入数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/save")
    public R<Void> insertBatchModelData(@Validated(AddGroup.class) @RequestBody IsfdThirPartyDataImportBo importBo,
                                        @RequestParam("redisKey") String redisKey) {
        // 获取参数
        Long modelId = importBo.getModelId();
        return toAjax(isfdDatabaseDataManagementService.confirmImportData(null));
    }


    /**
     * 铺层库-蒙皮层属性-查询/新增接口
     */
    @RepeatSubmit()
    @Log(title = "型材-查询/新增", businessType = BusinessType.INSERT)
    @PostMapping("/section/save")
    public R<IsfdSectionVo> querySectionProperties(@RequestBody IsfdSectionThirdPartyBo bo) {
        return R.ok(iIsfdThirdPartyAccessService.querySectionProperty(bo));
    }


    /**
     * 型材库-查询/新增接口
     */
    @RepeatSubmit()
    @Log(title = "蒙皮层属性-查询/新增", businessType = BusinessType.INSERT)
    @PostMapping("/layup/save")
    public R<IsfdLayupSkinPropertieVo> queryLayupProperties(@RequestBody IsfdLayupSkinPropertieThridPartyBo bo) {
        return R.ok(iIsfdThirdPartyAccessService.queryLayupSkinPropertie(bo));
    }

    /***
     * 铺层库-金属壳单元-查询/新增接口
     */
    @RepeatSubmit()
    @Log(title = "金属壳单元属性-查询/新增", businessType = BusinessType.INSERT)
    @PostMapping("/metal/save")
    public R<IsfdLayupMetalCaseMetaVo> queryMetalCaseProperties(@RequestBody IsfdLayupMetalCaseMetaBo bo) {
        return R.ok(iIsfdThirdPartyAccessService.queryLayupMetalCase(bo));
    }


    /**
     * 静强度分析-金属材料分页列表接口查询
     */
    @PostMapping("/staticStrengthAnalysis/matList")
    public TableDataInfo<IsfdMetalMaterialStaticStrengthAnalysisThirdPartyVo> staticStrengthAnalysisMatList(@RequestBody IsfdMetalMaterialStaticStrengthAnalysisQueryBo isfdMetalMaterialStaticStrengthAnalysisQueryBo) {
        return iIsfdThirdPartyAccessService.staticStrengthAnalysisMatList(isfdMetalMaterialStaticStrengthAnalysisQueryBo);
    }

    /**
     * 参数化建模模型库-保存接口
     */
    @PostMapping("/parametric/model/save")
    public R<Void> saveParametricModel(@RequestBody IsfdModelParametricBo bo) {
        return toAjax(iIsfdThirdPartyAccessService.saveParametricModel(bo));
    }

    /**
     * 参数化建模模型库-查询接口
     */
    @PostMapping("/parametric/model/list")
    public TableDataInfo<IsfdModelParametricVo> queryParametricModelList(@RequestBody IsfdModelParametricQueryThirdPartyBo queryBo) {
        return iIsfdThirdPartyAccessService.queryParametricModelList(queryBo);
    }

    /**
     * 结构分析通用前处理模型库-保存接口
     */
    @PostMapping("/preProcess/model/save")
    public R<Void> savePreprocessModel(@RequestBody IsfdModelGeneralPreprocessBo bo) {
        return toAjax(iIsfdThirdPartyAccessService.savePreprocessModel(bo));
    }

    /**
     * 结构分析通用前处理模型库-查询接口
     */
    @PostMapping("/preProcess/model/list")
    public TableDataInfo<IsfdModelGeneralPreprocessVo> queryPreprocessModelList(@RequestBody IsfdModelGeneralPreprocessQueryThirdPartyBo queryBo) {
        return iIsfdThirdPartyAccessService.queryPreprocessModelList(queryBo);
    }

    /**
     * 结构分析通用前处理结果库-保存接口
     */
    @PostMapping("/preProcess/result/save")
    public R<Void> savePreprocessResult(@RequestBody IsfdResultGeneralPreprocessBo bo) {
        return toAjax(iIsfdThirdPartyAccessService.savePreprocessResult(bo));
    }

    /**
     * 结构分析通用前处理结果库-查询接口
     */
    @PostMapping("/preProcess/result/list")
    public TableDataInfo<IsfdResultGeneralPreprocessVo> queryPreprocessResultList(@RequestBody IsfdResultGeneralPreprocessQueryThirdPartyBo queryBo) {
        return iIsfdThirdPartyAccessService.queryPreprocessResultList(queryBo);
    }


    /**
     * 机型-部段接口
     */
    @PostMapping("/meshModelStructureDefinition/list")
    public TableDataInfo<IsfdMeshModelStructureDefinitionVo> meshModelStructureDefinitionList(@RequestBody IsfdMeshModelStructureDefinitionsQueryThirdPartyBo queryThirdPartyBo) {
        return iIsfdThirdPartyAccessService.meshModelStructureDefinitionList(queryThirdPartyBo);
    }

    /**
     * 机型编号获取批次编号列表接口
     */
    @GetMapping("/collectBatchHistory/list")
    public R<List<String>> collectBatchHistoryList(@RequestParam("modelNumber") String modelNumber) {
        return R.ok(iIsfdThirdPartyAccessService.collectBatchHistoryList(modelNumber));
    }

    /**
     * 机型编号获取轮次编号列表接口
     */
    @GetMapping("/collectRoundHistory/list")
    public R<List<String>> collectRoundHistoryList(@RequestParam("modelNumber") String modelNumber) {
        return R.ok(iIsfdThirdPartyAccessService.collectRoundHistoryList(modelNumber));
    }

    /**
     * 结构分析模型库库-保存接口
     */
    @PostMapping("/model/save")
    public R<Void> saveModel(@RequestBody IsfdModelBo bo) {
        return toAjax(iIsfdThirdPartyAccessService.saveModelInfo(bo));
    }

    /**
     * 保存载荷分析实验任务数据
     */
    @PostMapping("/load/experiment/save")
    public R<Void> loadExperimentSave(@RequestBody IsfdLoadExperimentThridPartyBo isfdLoadExperimentThridPartyBo) {
        return toAjax(iIsfdThirdPartyAccessService.loadExperimentSave(isfdLoadExperimentThridPartyBo));
    }
}
